/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaswingapp;

import java.awt.*;
import javax.swing.*;
import JavaSwingApp.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 *
 * @author Alex
 */
public class JavaSwingApp extends JFrame implements ActionListener {
    public static final Dimension FRAMESIZE = new Dimension(600, 400);
    
    // Lists
    private JComboBox entertainment;
    private JComboBox venues;
    private JDialog datesparent;
    private DateChooser dates;
    private JComboBox results;
    
    // Buttons
    private JButton dateLaunch;
    private JButton search;
    private JButton purchaseTickets;
    
    // Space Takers
    private JButton space1;
    private JButton space2;
    
    /**
     * @param args the command line arguments
     */
    
    public JavaSwingApp() {
        super("Box Office");
        
        drawWindow();
        
        layoutStuff();
        
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }
    
    public void drawWindow() {
        entertainment = new JComboBox();
        venues = new JComboBox();
        datesparent = new JDialog();
        dates = new DateChooser(datesparent);
        
        dateLaunch = new JButton("Choose Date");
        search = new JButton("Search");
        purchaseTickets = new JButton("Purchase Tickets");
        space1 = new JButton("space");
        space2 = new JButton("null");
        
        results = new JComboBox();
    }
    
    private JPanel drawNorth() {
        
        JPanel northBorder = new JPanel(new GridLayout(1, 2));
        Event[] events = EventData.getEvents();
        
        northBorder.add(entertainment, BorderLayout.NORTH);
        entertainment.addItem(new String(events[0].getType()));
        entertainment.addItem(new String(events[1].getType()));
        northBorder.add(venues, BorderLayout.NORTH);
        northBorder.add(dateLaunch, BorderLayout.NORTH);
        
        northBorder.add(space1, BorderLayout.SOUTH);
        
        return northBorder;
    }
    
    private JPanel drawWest() {
        JPanel westBorder = new JPanel(new GridLayout(8,0));
        
        westBorder.add(space1, BorderLayout.WEST);
        space1.setVisible(false);
        space1.setEnabled(false);
        
        westBorder.add(search, BorderLayout.WEST);
        
        westBorder.add(purchaseTickets, BorderLayout.WEST);
        purchaseTickets.setEnabled(false);
        
        westBorder.add(space2, BorderLayout.WEST);
        space2.setVisible(false);
        space2.setEnabled(false);
        
        return westBorder;
    }
    
    private JPanel drawCenter() {
        JPanel centerBorder = new JPanel(new GridLayout(2,0));
        
        centerBorder.add(results, BorderLayout.CENTER);
        results.addItem(new String("I am also a string in a combo box :D"));
        results.addItem(new String("I am a string in a combo box :D"));
        
        return centerBorder;
    }
    
    public void layoutStuff() {        
        Container content = this.getContentPane();
        
        content.setLayout(new BorderLayout());
        
        JPanel northBorder = drawNorth();
        JPanel westBorder = drawWest();
        JPanel centerBorder = drawCenter();
        
        content.add(northBorder, BorderLayout.NORTH);
        
        content.add(westBorder, BorderLayout.WEST);
        
        content.add(centerBorder, BorderLayout.CENTER);
        
        this.setSize(FRAMESIZE);
        this.setPreferredSize(FRAMESIZE);
        this.setVisible(true);
    }
    
    public static void main(String[] args) {
        new JavaSwingApp();
    }
    
    @Override
    public void actionPerformed(ActionEvent e) {
        
    }
}
